package com.kt.app.ui.components


import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Discount
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Icon
import androidx.compose.material3.LeadingIconTab
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp

@Composable
fun TabSample() {
    var selectIndex by  remember {
        mutableStateOf(0)
    }
    val tabs = listOf("推荐", "视频", "直播", "图片", "游戏", "小程序")
    // 方式 一
//    TabRow(selectedTabIndex = selectIndex, indicator = {}, divider = {}, modifier = Modifier.fillMaxWidth().padding(3.dp)) {
//        tabs.forEachIndexed { index, title ->
//            Text(
//                text=title,
//                color=if(index == selectIndex) Color.Red else Color.Black,
//                textAlign = TextAlign.Center,
//                modifier = Modifier.clickable {
//                    selectIndex = index
//                }.padding(5.dp))
//        }
//    }
    // 方式 二
//    TabRow(selectedTabIndex = selectIndex,indicator = {}, divider = {}, modifier = Modifier.fillMaxWidth().padding(3.dp)) {
//        Tab(selected = selectIndex==0, onClick = {  selectIndex = 0}, unselectedContentColor = Color.Gray, selectedContentColor = Color.Red) {
//            Icon(imageVector = Icons.Default.Home, contentDescription = null)
//            Text(text="首页",textAlign = TextAlign.Center)
//        }
//        Tab(selected = selectIndex==1, onClick = {  selectIndex = 1},unselectedContentColor = Color.Gray, selectedContentColor = Color.Red) {
//            Icon(imageVector = Icons.Default.Discount, contentDescription = null)
//            Text(text="发现",textAlign = TextAlign.Center)
//        }
//    }

    TabRow(
        selectedTabIndex = selectIndex,
        indicator = {},
        divider = {},
//        modifier = Modifier.fillMaxWidth().padding(3.dp)
    ){
        LeadingIconTab(
           selected = selectIndex==0,
           onClick = {selectIndex=0},
           unselectedContentColor = Color.Gray,
           selectedContentColor = Color.Red,
           text = { Text(text="首页",textAlign = TextAlign.Center)},
           icon =  {Icon(imageVector = Icons.Default.Home, contentDescription = null)},
       )
        LeadingIconTab(
            selected = selectIndex==1,
            onClick = {selectIndex=1},
            unselectedContentColor = Color.Gray,
            selectedContentColor = Color.Red,
            text = { Text(text="发现",textAlign = TextAlign.Center)},
            icon =  {Icon(imageVector = Icons.Default.Discount, contentDescription = null)},
        )
        Tab(
            selected = selectIndex==2,
            onClick = {selectIndex=2},
            unselectedContentColor = Color.Gray,
            selectedContentColor = Color.Red,
            text = { Text(text="我的",textAlign = TextAlign.Center)},
            icon =  {Icon(imageVector = Icons.Default.Person, contentDescription = null)},
        )
    }




}

@Preview
@Composable
fun TabSamplePreview() {
    TabSample()
}

